﻿/*
*   专家动态
*/
angular.module('jisuStuHome')
.controller('expertdynamicController', ['$scope', '$rootScope', '$state', 'StuRequestTrain', 'interlocutionservice', 'sysUserInfo', 'Msg', 'T', 'LS', function ($scope, $rootScope, $state, ST, IS, sysUserInfo, Msg, T, LS) {

    //初始
    $scope.init = function () {
        $rootScope.parstr = "home.interlocution";
        $rootScope.twoparstr = "home.interlocution.expertdynamic";
        $scope.userinfo = sysUserInfo.getuserinfo();
        $scope.expertInfo = LS.getLS($scope.userInfo.user_ID + '_expert'); //当前列表所属栏目对象
        
        $scope.reloadCheck();
        //查询关注的专家的参数
        $scope.params = {
            userid: sysUserInfo.getuserinfo().user_ID,
            orgid: sysUserInfo.getuserinfo().organization_ID,
            expertid: $scope.expertInfo.userId,
            pageIndex: 1,
            pageSize: 10
        };
    }
    //返回主页，专栏列表
    $scope.backHome = function () {
        $rootScope.twoparstr = "home.interlocution";
        $rootScope.parstr = "home.interlocution";
        $state.go($rootScope.twoparstr);
    }
    //路由跳转详情页面
    $scope.openQuestInfo = function (item) {
        $rootScope.twoparstr = "home.interlocution.questiondetail";
        $rootScope.parstr = "home.interlocution";
        item.qrList = [];
        LS.setLS(sysUserInfo.getuserinfo().user_ID + '_ques', item);
        $state.go($rootScope.twoparstr);
    }
    //加载时判断
    $scope.reloadCheck = function () {
        //返回首页
        if ($scope.expertInfo == null || $scope.expertInfo == "" || $scope.expertInfo == undefined) {
            $rootScope.twoparstr = "home.interlocution";
        }
        $state.go($rootScope.twoparstr);
    }
    //初始
    $scope.init();
    /**********************************专家***********************************/
    $scope.getList = function () {
        IS.findSpecialDynamic($scope.params).then(function (response) {
            $scope.Loading = false;
            if (response.errorcode == "0") {
                $scope.List = response.datas; //我关注的专家
                $scope.paginationConf.totalItems = response.numCount;
                $scope.paginationConf.currentPage = response.pageIndex;
            } else {
                Msg.error("查询异常!")
            }
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }
    //取消或新增关注（专家）
    $scope.abolishConcern = function (item) {
        $scope.Loading = true;
        var param = { expertId: $scope.expertInfo.expertId, expertUserId: $scope.expertInfo.userId, userId: sysUserInfo.getuserinfo().user_ID };
        IS.addFollow(param).then(function (response) {
            if (response.errorcode == "0") {
                if ($scope.isFollowExpert) {
                    Msg.success("已取消关注！");
                    $rootScope.TJInfo.followzjNum = $rootScope.TJInfo.followzjNum - 1; //修改收藏专家数量
                } else {
                    Msg.success("关注成功！");
                    $rootScope.TJInfo.followzjNum = $rootScope.TJInfo.followzjNum + 1; //修改收藏专家数量
                }
                $scope.isFollowExpert = !$scope.isFollowExpert;
            } else {
                Msg.error("操作异常!")
            }
            $scope.Loading = false;
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }
    //默认为未关注
    $scope.isFollowExpert = false;
    //查询该专家是否关注
    $scope.findIsFollowExpert = function () {
        IS.getIsFollExpert({ userid: sysUserInfo.getuserinfo().user_ID, expertid: $scope.expertInfo.expertId }).then(function (response) {
            if (response.errorcode == "0") {
                if (response.datas.length > 0) {
                    $scope.isFollowExpert = true;
                }
            } else {
                Msg.error("操作异常!")
            }
            $scope.Loading = false;
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }
	$scope.findIsFollowExpert();
    /*********************************************************************/
    //配置分页
    $scope.paginationConf = {
        currentPage: 1, //$location.search().currentPage ? $location.search().currentPage :  当前页码
        totalItems: 0,  // 总的记录数
        itemsPerPage: 10, // 每页显示多少条        
        perPageOptions: [10, 20],   // 每页显示记录数        
        onChange: function () {
            $scope.paginationConf.currentPage = $scope.paginationConf.currentPage == 0 ? 1 : $scope.paginationConf.currentPage;
            $scope.params.pageIndex = $scope.paginationConf.currentPage;
            $scope.params.pageSize = $scope.paginationConf.itemsPerPage;
            $scope.getList();
        }
    };
} ]);




